package cn.itrip.auth.service;

import cn.itrip.beans.pojo.ItripUser;
import cn.itrip.mapper.itripUser.ItripUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author yaozhaobao
 * @Date 2020/12/11 15:46
 * @Version 1.0
 **/
@Service
public class UserServiceImpl implements  UserService {

    @Autowired
    ItripUserMapper itripUserMapper;



    @Override
    public boolean checkUserByUserCode(String userCode) throws Exception {
          Map map =new HashMap();
          map.put("userCode",userCode);
          map.put("activated","1");
         Integer rs =itripUserMapper.getItripUserCountByMap(map);
          if(rs==null||rs==0){
              return true;
          }else{
              return false;
          }
    }

    @Override
    public boolean itripxAddUserByPhone(ItripUser itripUser) throws Exception {
        if(itripUserMapper.insertItripUser(itripUser)>0){
            return  true;
        }
        return false ;
    }

    @Override
    public ItripUser getUserByUserCode(String userCode) throws Exception {
    return itripUserMapper.getItripUserByuserCode(userCode);
    }

    @Override
    public boolean itripxupdateUser(ItripUser itripUser) throws Exception {
        if(itripUserMapper.updateItripUser(itripUser)>0){
            return  true;
        }
        return false;
    }

    @Override
    public ItripUser checkLogin(String userCode, String password) throws Exception {
        ItripUser itripUser = itripUserMapper.getItripUserByuserCode(userCode);
        if(itripUser.getUserPassword().equals(password)) {
            return itripUser;
        }
        return null;
    }
}
